package org.czx.datactruct.fifth;

import java.util.LinkedList;
import java.util.List;

/**
 * 由于jdk自带的Stack有很大的设计缺陷，这里自己实现一个简陋的栈
 * @author czx
 * @date 2020/9/5 16:55
 */
public class OurStack<T> implements StackInterface<T> {
    private final List<T> list = new LinkedList<>();

    @Override
    public void push(T newEntry) {
        list.add(0, newEntry);
    }

    @Override
    public T pop() {
        T result = list.get(0);
        return list.remove(0);
    }

    @Override
    public T peek() {
        return list.get(0);
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void clear() {
        list.clear();
    }
}
